﻿/*
 * Created by SharpDevelop.
 * User: IEscarro
 * Date: 8/25/2009
 * Time: 1:52 PM
 * 
 * To change this template use Tools | Options | Coding | Edit Standard Headers.
 */

using System;
using System.Collections.Generic;

namespace Miming.Model
{
	/// <summary>
	/// Description of SalesReceipt.
	/// </summary>
	public class SalesReceipt
	{
		int id;
		Customer customer;
		Class _class;
		IList<SalesReceiptItem> items = new List<SalesReceiptItem>();
		CustomerMessage customerMessage;
		SalesTaxCode customerTaxCode;
		
		public SalesTaxCode CustomerTaxCode {
			get { return customerTaxCode; }
			set { customerTaxCode = value; }
		}
		
		public CustomerMessage CustomerMessage {
			get { return customerMessage; }
			set { customerMessage = value; }
		}
		Item taxItem;
		
		public Item TaxItem {
			get { return taxItem; }
			set { taxItem = value; }
		}
		string memo;
		
		public string Memo {
			get { return memo; }
			set { memo = value; }
		}
		
		public IList<SalesReceiptItem> Items {
			get { return items; }
			set { items = value; }
		}
		
		public Class Class {
			get { return _class; }
			set { _class = value; }
		}
		string saleNo;
		
		public string SaleNo {
			get { return saleNo; }
			set { saleNo = value; }
		}
		string soldTo;
		
		public string SoldTo {
			get { return soldTo; }
			set { soldTo = value; }
		}
		string checkNo;
		
		public string CheckNo {
			get { return checkNo; }
			set { checkNo = value; }
		}
		PaymentMethod paymentMethod;
		
		public PaymentMethod PaymentMethod {
			get { return paymentMethod; }
			set { paymentMethod = value; }
		}
		
		public Customer Customer {
			get { return customer; }
			set { customer = value; }
		}
		
		public int Id {
			get { return id; }
			set { id = value; }
		}
		DateTime date = DateTime.Now;
		
		public DateTime Date {
			get { return date; }
			set { date = value; }
		}
		
		public SalesReceipt()
		{
		}
		
		public virtual void AddItem(SalesReceiptItem item)
		{
			item.Receipt = this;
			items.Insert(0, item);
			OnItemAdded(null);
		}
		
		protected virtual void OnItemAdded(EventArgs e)
		{
			if (ItemAdded != null) {
				ItemAdded(this, e);
			}
		}
		
		public virtual event EventHandler ItemAdded;
	}
	
	public class SalesReceiptItem
	{
		Item item;
		
		public Item Item {
			get { return item; }
			set { item = value; }
		}
		SalesReceipt receipt;
		
		public SalesReceipt Receipt {
			get { return receipt; }
			set { receipt = value; }
		}
		int id;
		
		public int Id {
			get { return id; }
			set { id = value; }
		}
		double quantity;
		
		public double Quantity {
			get { return quantity; }
			set { quantity = value; }
		}
		
		public SalesReceiptItem()
		{
		}
		
		public SalesReceiptItem(Item item) : this(item, 1)
		{
		}
		
		public SalesReceiptItem(Item item, double quantity)
		{
			this.item = item;
			this.quantity = quantity;
		}
	}
}
